package com.jhy.study2;

import com.jhy.study2.singleton.*;

public class SingletonTestor1 {
    /**
     * @author: robert
     * @description: 单例模式测试
     * @date: 2021/8/22 15:49
     * @return
     */
    public static void main(String[] args) {
//        checkSingletonClass1();
//        checkSingletonClass2();
//        checkSingletonClass3();
//        checkSingletonClass4();
        checkSingletonClass5();



    }

    public static void checkSingletonClass1(){
        //        SingletonClass1 s1 = new SingletonClass1(); //不能new 构造方法私有
        SingletonClass1 s1 = SingletonClass1.getInstance();
        SingletonClass1 s2 = SingletonClass1.getInstance();
        System.out.println("s1:"+s1.hashCode());
        System.out.println("s2:"+s2.hashCode());
        System.out.println("s1==s2:"+(s1==s2));
    }


    public static void checkSingletonClass2(){
//                SingletonClass2 s1 = new SingletonClass2(); //不能new 构造方法私有
                SingletonClass2 s1 = SingletonClass2.getInstance();
                SingletonClass2 s2 = SingletonClass2.getInstance();
                System.out.println("s1:"+s1.hashCode());
                System.out.println("s2:"+s2.hashCode());
                System.out.println("s1==s2:"+(s1==s2));

    }
    public static void checkSingletonClass3(){
//                SingletonClass3 s1 = new SingletonClass3(); //不能new 构造方法私有
                SingletonClass3 s1 = SingletonClass3.getInstance();
                SingletonClass3 s2 = SingletonClass3.getInstance();
                System.out.println("s1:"+s1.hashCode());
                System.out.println("s2:"+s2.hashCode());
                System.out.println("s1==s2:"+(s1==s2));

    }
    public static void checkSingletonClass4(){
        SingletonClass4 s1 = SingletonClass4.getInstance();
        SingletonClass4 s2 = SingletonClass4.getInstance();
        System.out.println("s1:"+s1.hashCode());
        System.out.println("s2:"+s2.hashCode());
        System.out.println("s1==s2:"+(s1==s2));

    }

    public static void checkSingletonClass5(){
        SingletonClass5 s1 = SingletonClass5.INSTANCE;
        System.out.println(s1);
        SingletonClass5[] s5s = SingletonClass5.values();
        System.out.println("============================");
        for(SingletonClass5 obj : s5s){
            System.out.println("obj\'s ordinal:" + obj.ordinal() + " - " + obj.toString());
        }
        System.out.println("============================");
        System.out.println(SingletonClass5.valueOf("RED"));
    }

}
